package org.vaadin.nf4v.ext.config.menu;

import org.vaadin.nf4v.core.config.ContextConfig;
import org.vaadin.nf4v.core.config.NavigationConfig;
import org.vaadin.nf4v.core.config.PageConfig;

/**
 * Utility class for accessing menu item descriptions tree.
 * ContextConfig could have named menu item (this name takes part in page paths or
 * empty (grouping) menu item which is just grouping page menu item trees.
 * <p/>
 * PageConfig could have only named menu item or don't have it at all.
 * <p/>
 * MenuItemDescription provides access to complete context menu tree
 * (it's bidirectional tree)
 */
public class ExtMenuUtil {

    /**
     * @param config page config
     * @return menu item descriptor of page or null if not found
     */
    public static MenuItemDescription getMenuItem(PageConfig config) {
        return config.getAttribute(MenuAnnotationParser.MENU);
    }

    /**
     * Note: if @Menu annotation wasn't explicitly set for window class,
     * context will still contain "empty" menu item, used for grouping of page items
     *
     * @param config context config
     * @return manu item descriptor for context or null if not found
     */
    public static MenuItemDescription getMenuItem(ContextConfig config) {
        return config.getAttribute(MenuAnnotationParser.MENU);
    }

    /**
     * Note: navigation config holds "empty" menu item.
     * It is used just for grouping of contexts navigation menu trees.
     * Contexts doesn't see this item as parent.
     *
     * @param config navigation config
     * @return menu item descriptors tree root or null is @Menu annotation wasn't used at all
     */
    public static MenuItemDescription getMenuItem(NavigationConfig config) {
        return config.getAttribute(MenuAnnotationParser.MENU);
    }
}
